/**   
 * @Title: DaletouTermInfoCommunicater.java 
 * @Package: com.esun.rabbit2.communicaters.mainthread 
 * @Description: 大乐透期号通讯 
 * @Author: Miko baoz@500wan.com   
 * @Date: 2011-7-5 上午11:11:44  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.mainthread;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;

import com.esun.config.BussinessCode;
import com.esun.config.Key;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: DaletouTermInfoCommunicater
 * @Description: 大乐透期号通讯类
 * @Author: Miko baoz@500wan.com
 * @Date: 2011-7-5 上午11:11:44
 * 
 */
public class DaletouTermInfoCommunicater extends ServerCommunicater {

	private ArrayList<Hashtable<String, String>> alCache;

	public boolean getTermInfo() {

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> hm = new HashMap<String, String>();

		hm.put(BussinessCode.PASER_MID, BussinessCode.MID_DALETOU_TIMELEFT);
		list.add(hm);

		try {
			super.getServerResponse(list, true);

			if (super.getState() == 100) {

				updateLocalCach();
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			return false;
		}
	}

	private void updateLocalCach() {
		alCache = super.getListResult();
	}

	public Hashtable<String, String> getCurrentTerm() {

		Hashtable<String, String> htDataTmp = new Hashtable<String, String>();
		for (int i = 0; i < alCache.size(); i++) {
			htDataTmp = alCache.get(i);
			if (Integer.parseInt(htDataTmp.get(Key.KEY_ACTIVE)) == 1) {
				break;
			}
		}
		return htDataTmp;
	}

	public String getNexttTerm() {

		Hashtable<String, String> htDataTmp = new Hashtable<String, String>();
		for (int i = 0; i < alCache.size(); i++) {
			htDataTmp = alCache.get(i);
			if (Integer.parseInt(htDataTmp.get(Key.KEY_ACTIVE)) == 0) {
				break;
			}
		}
		return htDataTmp.get(Key.KEY_EXPECT);
	}

}
